﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ToracTechnologies.ExpressionTree.Testing;
using ToracTechnologies.ExpressionTreeLibrary.DynamicApi.Framework;

namespace ToracTechnologies.ExpressionTree.Testing.DynamicApi
{

    [TestClass]
    public class DynamicApiParameterBuilderUnitTest
    {

        #region String Based

        [TestMethod]
        public void BuildParameterFromStringName_Test1()
        {
            var j = new Jason()
                {
                    Id = 1,
                    txt = "Test"
                };

            var result = ParameterBuilder.BuildParameterFromStringName<Jason>("txt");

            Assert.IsNotNull(result.PropertyMemberExpression);
            Assert.IsNotNull(result.PropertyMemberExpression);
        }

        #endregion

        #region Func - Lambda Based

        [TestMethod]
        public void BuildParameterFromLinqPropertySelector_Test1()
        {
            var j = new Jason()
            {
                Id = 1,
                txt = "Test"
            };

            var result = ParameterBuilder.BuildParameterFromLinqPropertySelector<Jason>(x => x.txt);

            Assert.IsNotNull(result.PropertyMemberExpression);
            Assert.IsNotNull(result.ParametersForExpression);
        }

        [TestMethod]
        public void BuildParameterFromLinqPropertySelector_Test2()
        {
            var j = new Jason()
            {
                Id = 1,
                txt = "Test"
            };

            var result = ParameterBuilder.BuildParameterFromLinqPropertySelector<Jason>(x => x.Id);

            Assert.IsNotNull(result.PropertyMemberExpression);
            Assert.IsNotNull(result.ParametersForExpression);
        }

        [TestMethod]
        public void BuildParameterFromLinqPropertySelector_Test3()
        {
            var j = new Jason()
            {
                Id = 1,
                txt = "Test"
            };

            var result = ParameterBuilder.BuildParameterFromLinqPropertySelector<Jason>(x => x.IdNull);

            Assert.IsNotNull(result.PropertyMemberExpression);
            Assert.IsNotNull(result.ParametersForExpression);
        }

        #endregion

    }
}


